<template>
  <div>
    <p class="title">推荐歌单</p>
    <van-row gutter="10">
      <van-col span="8" v-for="obj in list1" :key="obj.id">
        <van-image fit="contain" :src="obj.picUrl" />
        <p class="fz">{{ obj.name }}</p>
      </van-col>
    </van-row>
    <!-- 音乐列表系列 -->
    <p class="title">音乐列表</p>
    <!-- vant组件库之list组件 -->
    <div>
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
      >
        <van-cell v-for="item in list" :key="item.id">
          <template>
            <div class="song_item_wrap">
              <div class="song_left">
                <p>{{ item.name }}</p>
                <p>
                  <span>{{ item.song.artists[0].name }} - </span>
                  <span>{{ item.song.album.name }}</span>
                </p>
              </div>
              <div class="song_right">
                <i class="iconfont icon-bofang"></i>
              </div>
            </div>
          </template>
        </van-cell>
      </van-list>
    </div>
  </div>
</template>

<script>
import { recommed, song } from "../api/index";
export default {
  data() {
    return {
      list1: [],
      list: [],
      loading: false,
      finished: false,
    };
  },
  methods: {
    onLoad() {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求
      this.getSong();
      this.finished = true;
    },
    async getSong() {
      let reg = await song({
        limit: 10,
      });
      // console.log(reg);
      this.list = reg.data.result;
      console.log(this.list);
    },
  },
  async created() {
    //请求的推荐数据
    let res = await recommed();
    this.list1 = res.data.result;
    //请求的音乐数据
  },
};
</script>

<style>
.title {
  padding: 0.266667rem 0.24rem;
  margin: 0 0 0.24rem 0;
  background-color: #eee;
  color: #333;
  font-size: 15px;
}
.song_name {
  font-size: 0.346667rem;
  padding: 0 0.08rem;
}
.fz {
  font-size: 10px;
}
.song_item_wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
/* 歌曲列表 */
.song_right {
  padding-right: 0.266667rem;
  line-height: 1.066667rem;
}

/* 歌曲_名字 */
.song_left {
  width: 8rem;
}
.song_left p:first-child {
  font-size: 0.453333rem;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.song_left p:last-child {
  font-size: 0.32rem;
  color: #888;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 播放图标 */
.song_right i {
  display: inline-block;
  transform: scale(1.3);
}
</style>